<?php namespace App\Http\Controllers\user\uc\gov;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use App\Models\News;
use Input;
use Session;
use Validator;
use Illuminate\Pagination\LengthAwarePaginator;
use Landish\Pagination\Pagination as BootstrapPresenter;

class NewsController extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		$uid = $this->getUid();
		$model = News::where("uid", $uid);
		if($model->count()){
			$numPerPage = 20;
			$count = $model->count();

			$curPage = (int)Input::get("page");
			if(!$curPage){
				$curPage = 1;
			}
			$p = new LengthAwarePaginator($model, $count, $numPerPage, $curPage);
			$p->setPath("");
	        $presenter = new BootstrapPresenter($p);
	        $data = $model->skip(($curPage - 1) * $numPerPage)->take($numPerPage)->get()->toArray();

		}else{
			$data = array();
			$presenter = '';
		}
		return view('user.uc.gov.news', ['data' => $data])->withPresenter($presenter)->withIsGovNews(true);
	}

	public function editNews()
	{
		return view("user.uc.gov.edit_news")->withIsGovNews(true);
	}

	public function addNews()
	{
		return view("user.uc.gov.add_news")->withIsGovNews(true);
	}

	public function newsDetail()
	{
		return view("user.uc.gov.news_detail")->withIsGovNews(true);
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}


	public function getNews()
	{
		$nid = Input::get('nid');
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}
}
